/*
 * @Author: Yang Zhang
 * @Date: 2021-11-18 22:21:44
 * @LastEditors: Yang Zhang
 * @LastEditTime: 2021-12-02 19:53:56
 * @Description: 权限校验
 */

import NProgress from 'nprogress'
import router from './router'
import { RouteLocationNormalized } from 'vue-router'
import store from './store'

// NProgress.configure({ showSpinner: false })
const whiteList: string | string[] = []

router.beforeEach(async (to: RouteLocationNormalized, _: RouteLocationNormalized, next: any) => {
  NProgress.start()
  const token = store.getters.token
  const userStore: any = store.state.user

  if (token) {
    if (to.path === '/login') {
      next('/')
    }
    next()
  } else {
    if (whiteList.indexOf(to.path) !== -1 || to.meta.noAuth) {
      next()
    } else if (to.path === '/login') {
      next()
    } else {
      // next(`/login?redirect=${to.path}`)
      next(`/login`)
    }
  }
  NProgress.done()
})

// router.afterEach((to: RouteLocationNormalized) => {
//   ; (document as any).title = 'KOL'
// })

